<template>
  <u-modal
    v-model:visible="show"
    title="提示"
    :show-cancel-button="true"
    confirm-text="确认"
    cancel-text="取消"
    @confirm="cancelSubmit"
    :content="content"
  ></u-modal>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { cancelOrder } from '@/api/api'
import { report } from '@/utils/track'

const show = ref(false)
const content = ref('是否确认取消订单')

const emits = defineEmits(['getTabData'])

const cancel = () => {
  show.value = true
  content.value = '是否确认取消订单'
}

const data = reactive({
  orderNumber: ''
})

const showModal = (code) => {
  data.orderNumber = ''
  show.value = true
  data.orderNumber = code
}

defineExpose({
  showModal
})

const cancelSubmit = async () => {
  try {
    await cancelOrder({
      orderNumber: data.orderNumber
    })
    report({ name_zh: '取消订单', name: '取消订单' })
    uni.showToast({
      title: '取消成功',
      icon: 'success',
      duration: 2000,
      position: 'top'
    })
    emits('getTabData')
  } catch (e) {
    if (e.data.data.code === 1) {
      uni.showToast({
        title: e.data.data.msg,
        icon: 'none',
        duration: 2000,
        position: 'top'
      })
    }
  }
}
</script>
